package Batch::Simple::Result;
#use Modern::Perl;
use strict;
use warnings;
use Moose;

has 'stdout' => ( 
  is => 'rw',
  isa => 'Str',
  default => '',
);

has 'stderr' => ( 
  is => 'rw',
  isa => 'Str',
  default => '',
);

has 'status' => (
  is => 'rw',
  isa => 'Int',
  default => 0,
);

has 'separator' => ( 
  is => 'rw',
  isa => 'Str',
  default => '',
);

use overload q{""} => \&_toString, 
             bool  => \&_toBool,
             fallback => 1;

sub _toString {
  my $self = shift;

  $self->stderr.$self->separator.$self->stdout;
}

sub _toBool {
  my $self = shift;

  !$self->status;
}

1;
__END__
# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

Batch::Simple::Result - Objects describing a program execution

=head1 SYNOPSIS

  use Batch::Simple;

  my $x = Batch::Simple->new(command => q{echo 'hola'});
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => "hola\n");
  is_deeply($r, $expected, q{execution of 'echo'});
  is("$r", "hola\n", 'toString overloading works');

  my $x = Batch::Simple->new(command => q{echo}, options => [qw{hola  juan}]);
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => "hola juan\n");
  is_deeply($r, $expected, q{execution of 'echo' with options});

  my $x = Batch::Simple->new(q{echo 'hola'});
  my $r = $x->run;
  my $expected = Batch::Simple::Result->new( 'status' => 0, 'stderr' => '', 'stdout' => "hola\n");
  is_deeply($r, $expected, q{Not named call. Execution of 'echo'});

  my $s = 0;
  if ($r) { $s = 1 };
  is($s, 1, 'Overloading to bool works');

=head1 AUTHOR

casiano, E<lt>casiano.rodriguez.leon@gmail.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2011 by casiano

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.


